<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$this->addCssFile('/project/apps/ecga/styles/style.css');
$this->addCssFile('/project/apps/ecga/styles/datagrid.css');
$this->addCssFile('/project/apps/ecga/styles/product.css');
$this->addCssFile('/statics/js/facebox/css/facebox.css');
$this->addCssFile('/project/apps/ecga/styles/form.css');

$this->addScriptFile('/statics/js/tooltips/tooltips.js');
$this->addScriptFile('/statics/js/datagrid/datagrid.js');
$this->addScriptFile('/statics/js/facebox/facebox.js');
?>
<body>
    <?php $this->import('tips'); ?>
    <div class="action-header">
        <h3><?php $this->put('产品列表');?></h3>
        <p class="action-desc">
        	<?php $this->put('您可以在这里查看所有产品，或者点击这里');?>
        	<a href="?a=add" rel="facebox" id="addSku" title="添加产品"><?php $this->put('添加产品');?></a>。
        	<?php $this->put('点击这里可以');?>
        	<a href="skus.php?a=downImportSKUTemplate" rel="facebox" id="downImportSKUTemplate" title="下载渠道地址批量导入模版"><?php $this->put('下载渠道地址批量导入模版');?></a>,
        	或 <a href="skus.php?a=batchImportSKU" rel="facebox" id="batchImportSKU" title="批量导入产品渠道地址"><?php $this->put('批量导入产品渠道地址');?></a>,。
        </p>
    </div>
    <div class="action-filter">	
        <fieldset>
            <legend><?php $this->put('过滤器');?></legend>

        </fieldset>
    </div>
	<div class="action-filterform">
	<fieldset>
	 <form id="theForm" action="" method="GET">
	    <select name="projectId">
            <!-- <option value="">项目</option> -->
            <?php $this->htmlOptions($projects, $filter['projectId'])?>
        </select>
        <input type="text" class="tiptext" id="titleFilter" name="title" value="<?php $this->put($filter['title'])?>" title="产品名称" />
        <script>
    		new OverText($('titleFilter'));
        </script>
		<input type="text" class="tiptext" id="modelFileer" name="model" value="<?php $this->put($filter['model'])?>" title="产品Model" />
        <script>
			new OverText($('modelFileer'));
		</script>
		<select name="level">
           <option value="">星级</option>
            <?php $this->htmlOptions($levelArray, $filter['level'])?> 
        </select>
		<input type="text" class="tiptext" id="skuFilter" name="sku" value="<?php $this->put($filter['sku'])?>" title="P/N" />
        <script>
    		new OverText($('skuFilter'));
        </script>
        <button type="submit" onclick="this.form.action='?a=show'"><?php $this->put('确定');?></button>
    </form>

	</fieldset>
	</div>
    <div class="datagrid">
        <div class="gridbar nobg ">
            <div class="gridbar-left">
                <div class="form">
                    <select id="batchOptions">
                        <option value=""><?php $this->put('批量操作');?></option>
                        <!-- <option value="batchRemove" class="confirm:'<?php $this->put('您确定要删除选中项目吗?');?>'"><?php $this->put('删除');?></option> -->
                    </select>
                    <input type="button" id="batchBtn" class="button" value="<?php $this->put('确定');?>"/>
                </div>
             </div>
            <div class="pagelist-box">
                <div class="pagelist-box">
                <?php $this->htmlPageLinks($list, $uri) ?>
                </div>
            </div>
        </div>

    <!-- 快速编辑模板 -->
    <table id="inlineEditTable" class="inline-edit-form" style="display:none;"></table>

        <div style=" margin:0 20px; ">
            <table id="datagrid" class="datagrid-table" style="width:100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="lock-th">
                    <th class="first"><input type="checkbox"/></th>
					<th><?php $this->put('名称');?></th>
                    <th><?php $this->put('星级');?></th>
					<th><?php $this->put('Model');?></th>
					<th><?php $this->put('p/n');?></th>
                    <!--<th><?php $this->put('sku');?></th>-->
                    <th><?php $this->put('厂商建议零售价(SRP)');?></th>
                    <th><?php $this->put('协定价(MOP)');?></th>
                    <th><?php $this->put('总代出货价(DSP)');?></th>
                    <th><?php $this->put('备注');?></th>
                </tr>
        <?php if (!empty($list)): ?>
            <?php foreach ($list as $item): ?>
                <tr class="<?php $this->alternate();?>" recordid='<?php $this->put($item['id']);?>'>
                    <td class="first"><input type="checkbox" name="id[]" value="<?php $this->put($item['id']);?>"/></td>
                    <td>
                        <p class="title row-masterName"><?php $this->put($item['title']);?></p>
                        <p class="actions hidden">
                            <span><a href="#" rel="facebox" title="编辑" id="editSku_<?php $this->put($item['id']);?>">编辑</a></span>
                            <span><a href="#" rel="facebox" title="编辑/查看渠道采集地址" id="editSiteUrl_<?php $this->put($item['id']);?>">编辑/查看渠道采集地址</a></span>
                        </p>
                    </td>
					<td class="row-email"><?php $this->put($item['level']);?></td>
                    <td class="row-email"><?php $this->put($item['model']);?></td>
					<td class="row-email"><?php $this->put($item['sku']);?></td>
                    <!--<td class="row-email"><?php $this->put($item['sku']);?></td>-->
                    <td class="row-email"><?php $this->put($item['srp']);?></td>
                    <td class="row-email"><?php $this->put($item['mop']);?></td>
                    <td class="row-email"><?php $this->put($item['dsp']);?></td>
                    <td class="row-email"><?php $this->put($item['remark']);?></td>
                </tr>
            <?php endforeach; ?>
        <?php endif;?>
            </table>
            <?php $this->notFound($list) ?>
        </div>
        <div class="bottombar">
            <div class="gridbar-left">
                <span><?php $this->sprintf('共计 (%s) 条记录', $list->recordCount); ?></span>
                <span><?php $this->sprintf('显示 (%s - %s)', $list->start + 1, min($list->start + $list->pageSize , $list->recordCount)); ?></span>
            </div>
            <div class="pagelist-box">
                <?php $this->htmlPageLinks($list, $uri) ?>
            </div>
        </div>
    </div>
    <?php $this->import('footer'); ?>
<script type="text/javascript">
    window.addEvent('domready', function() {

        var dg = new DataGrid($("datagrid"), {
            "inlineEditTemplate": "inlineEditTable"
        });
        window.fb = new Facebox({showFooter: false, "width": "auto"});
        $$('a[id^=editSku_]').each(function(target, index){
            var tmp = target.id.split('_');
            target.href = '/skus.php?a=edit&id=' + tmp[1];
        });
        $$('a[id^=editSiteUrl_]').each(function(target, index){
            var tmp = target.id.split('_');
            target.href = '/skus.php?a=editSiteUrl&id=' + tmp[1];
        });
        $$('a[id=addSku]').each(function(target, index){
            target.href = 'skus.php?a=add';
        });
       
    });
    function checkSkuForm(tag) {
    	if (tag) {
    		if ($('title').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入产品名称';
                $('title').focus();
                return false;
            }
            if ($('sku').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入SKU';
                $('sku').focus();
                return false;
            }
            if ($('srp').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入厂商建议零售价';
                $('srp').focus();
                return false;
            }
            if ($('mop').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入协定价';
                $('mop').focus();
                return false;
            }
            if ($('projectId').value.trim() == '') {
                $('adviceMsg').innerHTML = '请选择项目';
                $('projectId').focus();
                return false;
            }
            var jsonRequest = new Request.JSON({
                url: $('skuForm').action,
                onComplete: function(res) {
                    if (res.result){
                       $('adviceMsg').set('class', 'validation-cmpltn');
                       location.reload(true);
                    }
                    $('adviceMsg').innerHTML = res.message;
                }
            }).post($('skuForm'));
        } else {
            window.fb.close();
        }
    }
    function checkSkuSiteUrlsForm(tag) {
    	if (tag) {
            var jsonRequest = new Request.JSON({
                url: $('skuSiteUrlsForm').action,
                onComplete: function(res) {
                    if (res.result){
                       $('adviceMsg').set('class', 'validation-cmpltn');
                       window.fb.close();
                    }
                    $('adviceMsg').innerHTML = res.message;
                }
            }).post($('skuSiteUrlsForm'));
        } else {
            window.fb.close();
        }
    }
    function checkBatchImportTemplateForm(tag) {
        if (tag) {
            var projectId = $('projectId').getSelected()[0].get('value');
            $('batchImportTemplateForm').action = $('batchImportTemplateForm').action + '&projectId=' + projectId;
            $('batchImportTemplateForm').submit();
        } else {
            window.fb.close();
        }
    }
    function checkBatchImportSKUForm(tag) {
        if (tag) {
            $('batchImportSKUForm').submit();
        } else {
            window.fb.close();
        }
    }
</script>
</body>
</html>
